package test;

import com.alibaba.fastjson.JSON;
import dao.User;
import utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class mysqltest {
    public static void main(String[] args) {
        // 数据库调用相关
        Connection connection = null;
        PreparedStatement pStatement = null;
        ResultSet rsSet = null;

        // 连接数据库
        connection = JDBCUtils.getConnection();
        // 创建sql语句 未来七天的
        String sql = "select userNum,userBir,TIMESTAMPDIFF(day,now(),userBir)from student where TIMESTAMPDIFF(day,now(),userBir)<=7 and TIMESTAMPDIFF(day,now(),userBir)>=0;";
        // 与上sql问号一一对应

        User user = new User();

        try {
            pStatement = connection.prepareStatement(sql);
//            pStatement.setString(1, userNum );
            rsSet = pStatement.executeQuery();
            if (rsSet.next()) {
                user.setUserNum(rsSet.getString("userName"));
                user.setUserNum(rsSet.getString("userBir"));
                System.out.println(JSON.toJSONString(user));
//                resp.getWriter().append(JSON.toJSONString(user));
            } else {
                System.out.println("none");
            }
            // 然后将这个用户发给前端
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            JDBCUtils.close(connection, pStatement, rsSet);    // 关闭连接
        }
    }
}
